package com.ethan.cj.ssm.service.impl;

import com.ethan.cj.ssm.dao.ClaimDao;
import com.ethan.cj.ssm.entity.Claim;
import com.ethan.cj.ssm.service.ClaimService;
import com.ethan.cj.ssm.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 债权打包逻辑处理层接口的实现
 */
@Service
public class ClaimServiceImpl implements ClaimService {
    /**
     * 债权打包dao层映射
     */
    @Autowired
    private ClaimDao cd;

    /**
     * 分页查询
     * @param map 查询条件
     * @return 债权打包对象
     */
    @Override
    public Map<Object,Object> selectClaim(PageBean<Claim> pb, Map<Object,Object> map) {
        if(map == null){
            map = new HashMap<>();
        }
        map.put("pb", pb);
        List<Claim> list=cd.selectClaim(map);
        for (Claim c : list) {
            if (c.getClstatus().equals("0"))
                c.setClstatus("待审核");
            if (c.getClstatus().equals("1"))
                c.setClstatus("已审核");
            if (c.getClstatus().equals("2"))
                c.setClstatus("已禁用");
        }
        int count=cd.count(map);
        if (list != null && list.size() > 0) {
            map.put("code", 0);
            map.put("msg", "");
            map.put("data", list);
            map.put("count", count);
        } else {
            map.put("code", 1);
            map.put("msg", "无数据");
        }
        return map;
    }

    /**
     * 获取总条数
     *
     * @return 总条数
     */
    @Override
    public int count( Map<Object,Object> params) {
        return cd.count(params);
    }

    /**
     * 查询债权打包所有信息
     * @return 债权打包 json对象
     */
    @Override
    public Map<Object,Object> selClaimList() {
        List<String> list = cd.selClaimList();
        List<String> array = new ArrayList<>();
        for (String str : list) {
            if (str.equals("0"))
                str = "待审核";
            if (str.equals("1"))
                str = "已审核";
            if (str.equals("2"))
                str = "已禁用";
            array.add(str);
        }
        Map<Object,Object> result = new HashMap<>();
        if (list != null && list.size() > 0) {
            result.put("code", 0);
            result.put("msg", "");
            result.put("data", array);
        } else {
            result.put("code", 1);
            result.put("msg", "无数据");
        }
        return result;
    }
}
